Imports System.Net
Imports System.Text
Imports System.Threading

Module _4chan
    Public Function RandomNumber(ByVal MaxNumber As Integer, _
Optional ByVal MinNumber As Integer = 0) As Integer

        'initialize random number generator
        Dim r As New Random(System.DateTime.Now.Millisecond)

        'if passed incorrect arguments, swap them
        'can also throw exception or return 0

        If MinNumber > MaxNumber Then
            Dim t As Integer = MinNumber
            MinNumber = MaxNumber
            MaxNumber = t
        End If

        Return r.Next(MinNumber, MaxNumber)

    End Function
    Dim q As String = Chr(34)
    Private Sub chanspam(ByVal msg As String)
        Do Until 1 = 2
            post(msg)
            Threading.Thread.sleep(10000)
        Loop
    End Sub
    Public Sub postforever(ByVal msg As String)
        Dim threadx As Thread = New Threading.Thread(New ParameterizedThreadStart(AddressOf chanspam))
        threadx.Start(msg)

    End Sub
    Public Function post(ByVal txtmsg As String) As String

retry:
        Dim web As New WebClient()
        Dim templist As New ListBox
        Dim postid As String
        Dim strHTML As String = web.DownloadString("http://img.4chan.org/b/imgboard.html")

        'search1 = &nbsp; [<a href="
        'search2 = ">
        GBA(strHTML, "&nbsp; [<a href=" & q, q & ">", templist)

        If templist.Items.Count = 0 Then
            GoTo retry
        End If

retry2:

        Dim randomline As Integer = RandomNumber(1, templist.Items.Count.ToString)
        '    strHTML = web.DownloadString("http://www.img.4chan.org/b/" & templist.Items.Item(randomline).ToString)
        postid = GetBetween(templist.Items.Item(randomline).ToString, "res/", ".", 0)

        web.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
        Dim _
            d As Byte() = _
                Encoding.ASCII.GetBytes("com=" & txtmsg & "&resto=" & postid & "&mode=regist&MAX_FILE_SIZE=2097152&sub=&pwd=Mfu81wdN&uppfile=&filename=")
        Dim res As Byte() = web.UploadData("http://dat.4chan.org/b/imgboard.php", "POST", d)
        strHTML = (Encoding.ASCII.GetString(res))

        Return postid
    End Function
End Module